﻿

@model PagedList<Views_Goods>
@{
    ViewBag.Title = "在售物料列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    ProductListQueryModel paramModel = new ProductListQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (ProductListQueryModel)ViewBag.paramModel;
    }
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    Dictionary<string, string> labelDicTypeName = ReleaseBiz.GetLabelTypeNameDic();

}
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("SupplierProducts", "product")" method="get">
    <div class="form_query">
        <div>
            料号：
            <input type="text" name="MPN" id="MPN" class="abc input-default" placeholder="" value="@paramModel.MPN">&nbsp;
        </div><div>
            板块：
            <select id="label_type" name="label_type">
                <option value="-10" @(paramModel.label_type == -10 ? "selected" : "")>全部板块</option>
                @{
                    dc = new Dictionary<string, string>();
                    var list = YiYiTong.Rocket.Helper.EnumHelper.GetEnumItems(typeof(LabelType));
                    foreach (var item in list)
                    {
                        dc.Add(item.Value.ToString(), item.Description);
                    }
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.label_type.ToString());
            </select>&nbsp;
        </div><div>
            结束时间：
            <input type="text" name="end_time_begin" class="calendar calendar-time" id="end_time_begin" value="@paramModel.end_time_begin.ToString(1)"> - <input type="text" name="end_time_end" class="calendar calendar-time" id="end_time_end" value="@paramModel.end_time_end.ToString(1)">&nbsp;
            品牌：
            <select id="label_type" name="brand_id">
                <option value="-10">全部品牌</option>
                @{
                    dc = new Dictionary<string, string>();
                    dbcontext.ADZ_BrandMaster.Where(t => t.is_del == 0).ToList().ForEach(t =>
                    {
                        dc.Add(t.brand_id.ToString(), t.brand_name);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.brand_id.ToString())
            </select>&nbsp;
        </div><div>
            分类：
            <select id="category_id" name="category_id">
                <option value="-10">全部分类</option>
                @{
                    dc = new Dictionary<string, string>();
                    ADZ_GoodsCategoryBiz.Instance.GetParentSunList().ForEach(t =>
                    {
                        dc.Add(t.category_id.ToString(), t.category_name);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.category_id.ToString())
            </select>&nbsp;
        </div><div>
            是否上架：
            <select id="is_withdraw" name="is_withdraw">
                <option value="-10">全部</option>
                @{
                    dc = new Dictionary<string, string>();
                    dc.Add("0", "已上架");
                    dc.Add("1", "已下架");
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.is_withdraw.ToString());
            </select>&nbsp;
        </div><div>
            是否有库存：
            <select id="stock_amount" name="stock_amount">
                <option value="-10">全部</option>
                @{
                    dc = new Dictionary<string, string>();
                    dc.Add("0", "没库存");
                    dc.Add("1", "库存不足");
                    dc.Add("2", "库存充足");
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.stock_amount.ToString());
            </select>&nbsp;
        </div><div>
            上架时间：
            <input type="text" name="with_up_time_begin" class="calendar calendar-time" id="with_up_time_begin" value="@paramModel.with_up_time_begin.ToString(1)"> - <input type="text" name="with_up_time_end" class="calendar calendar-time" id="with_up_time_end" value="@paramModel.with_up_time_end.ToString(1)">&nbsp;
        </div><div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div><div>
            <button type="submit" class="btn btn-primary" id="formsubmit">查询</button>
        </div>
    </div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:40px">序号</th>
            <th style="width:65px">图片</th>
            <th>料号</th>
            <th>品牌</th>
            <th>分类</th>
            <th>供应商</th>
            <th>板块</th>
            <th>单位</th>
            <th>DC号</th>
            <th>库存数量</th>
            <th>卖出数量</th>
            <th>最小订购量</th>
            <th>价格</th>
            <th>币种</th>
            <th>市场价</th>
            <th>是否含税</th>
            <th>上架时间</th>
            <th>是否上架</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>
                    @m.goods_id
                </td>
                <td style="padding:5px 0 0 2px;">
                    @{
                        var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id).OrderBy(t => t.sort_NO).ThenBy(t => t.seq_id);
                        foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                        {
                            <a class="list-img" href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                        }
                    }
                </td>
                <td>@m.MPN</td>
                <td>@m.brand_name</td>
                <td>@m.category_name</td>
                <td>@m.supplier_name</td>
                <td>
                    <div>@labelDicTypeName[m.label_type.ToString()]</div>
                </td>
                <td>@m.goods_unit</td>
                <td>@m.DCN</td>
                <td>@m.stock_amount</td>

                <td>
                    @{
                        var all = from t in dbcontext.ADZ_OrderDetails
                                  join s in dbcontext.ADZ_OrderMaster on t.order_id equals s.order_id
                                  where t.goods_id == m.goods_id && s.is_succ == 1
                                  group t by new { t.goods_id, t.amount } into b
                                  select new
                                  {
                                      allcount = b.Sum(x => x.amount)
                                  };
                        var querydata = all.FirstOrDefault();
                        if (querydata != null)
                        {
                            <info>@all.First().allcount @m.goods_unit</info>
                        }
                        else
                        {
                            <info>- -</info>
                        }
                    }
                </td>

                <td>@m.min_amount</td>
                <td>@m.price</td>
                <td>
                    @switch (m.currency_type)
                    {
                        case 0:
                            @:<div class="">人民币</div>
                            break;
                        case 1:
                            @:<div class="red">美金</div>
                            break;
                    }
                </td>
                <td>@m.market_price</td>
                <td>
                    @switch (m.include_tax)
                    {
                        case 0:
                            @:<div class="">未含税</div>
                            break;
                        case 1:
                            @:<div class="green">含税</div>
                            break;
                    }
                </td>
                <td>@m.with_up_time.ToString(1)</td>
                <td>
                    @switch (m.is_withdraw)
                    {
                        case 0:
                            @:<div class="green">已上架 </div>
                            break;
                        case 1:
                            @:<div class="red">已下架 </div>
                            break;
                    }
                </td>
            </tr>
                            }

                        }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"]
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };
    reloadHandler = function ()
    {
        window.location.reload();
    }

    //下载列表
    $("#formsubmit").on("click", function () {
        $("#S_Form").attr("action", "@Url.Action("SupplierProducts", "product")");
        $("#S_Form").submit();
    });

    //下载列表
    $("#downloadexcel").on("click", function () {
        $("#S_Form").attr("action", "@Url.Action("downSupplierProducts", "product")");
        $("#S_Form").submit();
    });


</script>
